package com.tmxk.days01.demo3_pets_wmh;

import java.util.Scanner;

public class PetOperation {
    /**
     * 宠物的业务操作
     *
     * @param
     */
    //根据宠物商城提供的选项来判断当前选项是哪个具体的宠物信息。
    public Pet getPetInfo(int chooseType) {
         Pet pet = null;
         switch (chooseType) {
         case 1:
         pet = new Cat("小黄", 2, "中华田园犬", "黑白相间");

         break;
         case 2:
         pet = new Dog("小花", 2, "波斯猫", "黑白相间");

         break;
         case 3:
         pet = new Bird("小麻雀", 2, "麻雀", "灰色");
         break;
         case 4:
         pet = new Fish("小花猫", 2, "金鱼", "金色");
         break;
         case 5:
         pet = new Tortoise();
         pet.setName("小鬼");
         break;
         default:
         System.out.println("正在培育中");
         break;

         }
       return pet;
   }

    public void petEatOrShout(Pet pet) {
        //pet.shout();
        //pet.eat();

        //父类不能调用子类特有的方法，作用是判断当前父类引用是否是其子类具体事例
        if (pet instanceof Dog) {
            //狗特有方法看门
            Dog dog = (Dog) pet;
            dog.gatekeeper();
        } else if (pet instanceof Cat) {
            Cat cat = (Cat) pet;
            cat.catchMice();
        } else if
        (pet instanceof Fish) {
            ((Fish) pet).swimming();
        } else if (pet instanceof Bird) {
            ((Bird) pet).fly();
        }
    }
}

